﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AFanDa.Admin.filters
{
    public class LogFilters : ActionFilterAttribute
    {

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            // 如果返回值是Json类型 就会 转换成功
            // 否则为 null
            var result = filterContext.Result as JsonResult;

            if (result != null)
            {
                var obj = result.Data as Dto.Base.ApiResult;
                if (obj.data == null)
                {
                    filterContext.Result = new JsonResult()
                    {
                        Data = new
                        {
                            code = obj.code,
                            message = obj.message,
                        }
                    };
                }

            }

        }
    
    }
}